#include "loops.h"

Loop::Loop(std::string * type, class AbstractNode * cond, class AbstractNode * code) : AbstractNode()
{
	c_type=type;
	c_cond=cond;
	c_code=code;
}

void Loop::write(GraphStream * s)
{
	this->accept(s);

	fprintf(s->stream,"\tnode_%d [label=\"Loop node\\n%s\" shape=\"rectangle\"]\n", this->number(),c_type->c_str());
	c_cond->write(s);
	fprintf(s->stream,"\tnode_%d -> node_%d [label=\"condition\"]\n",this->number(),c_cond->number());
	c_code->write(s);
	fprintf(s->stream,"\tnode_%d -> node_%d [label=\"code\"]\n",this->number(),c_code->number());
}

Loop::~Loop(void)
{
	delete c_cond;
	delete c_code;
	delete c_type;
}

LoopToDo::LoopToDo(class AbstractNode * left, class AbstractNode * right, class AbstractNode * code) : AbstractNode()
{
	c_left=left;
	c_right=right;
	c_code=code;
}

void LoopToDo::write(GraphStream * s)
{
	this->accept(s);

	fprintf(s->stream,"\tnode_%d [label=\"Loop to do node\" shape=\"rectangle\"]\n", this->number());
	c_left->write(s);
	fprintf(s->stream,"\tnode_%d -> node_%d [label=\"left\"]\n",this->number(),c_left->number());
	c_right->write(s);
	fprintf(s->stream,"\tnode_%d -> node_%d [label=\"right\"]\n",this->number(),c_right->number());
	c_code->write(s);
	fprintf(s->stream,"\tnode_%d -> node_%d [label=\"code\"]\n",this->number(),c_code->number());
}

LoopToDo::~LoopToDo(void)
{
	delete c_left;
	delete c_right;
	delete c_code;
}
